import { TOP_CHANNELS } from '@/constants';
import Store from './Store';
import { LIST_NAME } from './constants';
import { HeaderForm, Table, ImportPriceModal, GoodsDetailModal, AdjustPriceByRangeModal } from './components';

export default {
  metaInfo: {
    title: '商品手动调价管理',
  },
  components: {
    [HeaderForm.name]: HeaderForm,
    [Table.name]: Table,
    [ImportPriceModal.name]: ImportPriceModal,
    [GoodsDetailModal.name]: GoodsDetailModal,
    [AdjustPriceByRangeModal.name]: AdjustPriceByRangeModal,
  },
  data() {
    return {
      store: new Store([{ listName: LIST_NAME }]),
      topChannelList: TOP_CHANNELS,
    };
  },
  methods: {
    handleCurrentChange() {},
    ...[
      'pageSizeChange',
      'pageNumChange',
      'queryGoodsList',
      'onCloseImportModal',
      'onOpenImportModal',
      'exportGoodsPrice',
      'onAdjustPriceByRange',
      'onCloseGoodsDetailModal',
      'onOpenGoodsDetailModal',
      'onAdjustPriceByRangeModalOK',
      'onAdjustPriceByRangeModalClose',
    ].reduce(
      (prev, curr) => ({
        ...prev,
        [curr](e) {
          if (curr === 'exportGoodsPrice') {
            this.store.formQueryValue = this.$refs.manualPrice.formQuery;
          }
          this.store[curr](e);
        },
      }),
      {},
    ),
  },
  computed: {
    ...[
      'formQueryValue',
      'list',
      'querying',
      'importVisible',
      'goodsDetailVisible',
      'goodsDetail',
      'cellularList',
      'exporting',
      'cellularMap',
      'competeStoreNames',
    ].reduce(
      (prev, curr) => ({
        ...prev,
        [curr]: {
          get() {
            if (curr === 'list') {
              const { data = [], ...restParams } = this.store[curr][LIST_NAME];
              this.store.querying = this.store[curr][LIST_NAME].loading;
              return {
                ...restParams,
                data: data,
              };
            }
            return this.store[curr];
          },
        },
      }),
      {},
    ),
    adjustPriceByRangeModalProps() {
      const { adjustPriceByRangeModalValue } = this.store;
      return { ...adjustPriceByRangeModalValue };
    },
  },
  async mounted() {
    // this.store.list.table.data = [{ costPrice:100,goodsCode: 5003543, channelName:'益丰大药房（长沙天元涉外店）',channelCode: 'MTWM_7432', cellularCode: '123456', cellularName: '长沙蜂窝01' }];
    this.store.init();
  },
};
